﻿@model ZDSoft.UPMS.Model.BusinessPart.SituationType
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>平时成绩管理系统--情况类型</title>
    <style type="text/css">
.ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
	</style>
    <link href="../../Content/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/css/demo.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.ztree.core-3.5.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.ztree.excheck-3.5.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.ztree.exedit-3.5.js" type="text/javascript"></script>
    <link href="../../Content/css/Common.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    
    </script>
    <script type="text/javascript">
       
        var setting = {
            view: {
                addHoverDom: addHoverDom,
                removeHoverDom: removeHoverDom,
                selectedMulti: false
            },
            edit: {
                enable: true,
                editNameSelectAll: true,
                showRemoveBtn: showRemoveBtn,
                showRenameBtn: showRenameBtn
            },
            data: {

                simpleData: {
                  enable: true

                }
            },
            callback: {
                beforeDrag: beforeDrag,
                beforeRemove: beforeRemove,
                beforeRename: beforeRename,
                onRename: onRename,
                  onRemove: onRemove
            }
        };
          
        function beforeDrag(treeId, treeNodes) {
            return false;
        };

        var zNodes = [
         @Html.Raw(TempData["type"].ToString())
		];

        function beforeRemove(treeId, treeNode) {
            var pNode = treeNode.getParentNode();
            if (pNode == null) {
                if (confirm('该节点为父节点，执行操作将删除所有相关节点，确定要删除吗？')) {
                    return true;
                }
                else { return false; }


            }
            var zTree = $.fn.zTree.getZTreeObj("treeSituationType");
            zTree.selectNode(treeNode);
        };
        function onRename(e, treeId, treeNode) {
            var parentNode = treeNode.getParentNode();
            var parentId = "";
            if (parentNode != null) {
                parentId = parentNode.id;
                }
            $.post("/SituationType/Create", { "id": treeNode.id, "pid": parentId, "name": treeNode.name },
            function (data) {
                treeNode.id = data;
                ss = data;
                var zTree = $.fn.zTree.getZTreeObj("treeSituationType");
                zTree.updateNode(treeNode);
            });
            k = false;

        }

        function onRemove(e, treeId, treeNode)
        {
          $.post("/SituationType/GetSituationByID", { "id":treeNode.id},
            function (data) {
                treeNode.id = data;
                ss = data;
                var zTree = $.fn.zTree.getZTreeObj("treeSituationType");
                zTree.updateNode(treeNode);
            });
        }
        function beforeRename(treeId, treeNode, newName) {
            if (newName.length == 0) {
                alert("节点名称不能为空.");
                var zTree = $.fn.zTree.getZTreeObj("treeSituationType");
                setTimeout(function () { zTree.editName(treeNode) }, 10);
                return false;
            }
            return true;
        };

        function showRemoveBtn(treeId, treeNode) {
            return true;
        };
        function showRenameBtn(treeId, treeNode) {
            return true;
        };

        var newCount = 1;
        function addHoverDom(treeId, treeNode) {
            var pNode = treeNode.getParentNode();
            if (pNode == null) {
                var sObj = $("#" + treeNode.tId + "_span");
                if (treeNode.editNameFlag || $("#addBtn_" + treeNode.id).length > 0) return;
                var addStr = "<span class='button add' id='addBtn_" + treeNode.id
				+ "' title='add node' onfocus='this.blur();'></span>";
                sObj.append(addStr);
                var btn = $("#addBtn_" + treeNode.id);
                if (btn) btn.bind("click", function () {
                    var zTree = $.fn.zTree.getZTreeObj("treeSituationType");
                    zTree.addNodes(treeNode, { id: (100 + newCount), pId: treeNode.id, name: "new SituationType" + (newCount++) });
                    return false;
                });
            }
        };

        function removeHoverDom(treeId, treeNode) {

            $("#addBtn_" + treeNode.id).unbind().remove();

        };
        function add(e) {
            var zTree = $.fn.zTree.getZTreeObj("treeSituationType"),
			isParent = e.data.isParent,
			nodes = zTree.getSelectedNodes(),
			treeNode = nodes[0];
            treeNode = zTree.addNodes(null, { id: (100 + newCount), pId: 0, isParent: isParent, name: "new SituationType" + (newCount++) });
        };


        $(document).ready(function () {
         
         $.fn.zTree.init($("#treeSituationType"), setting,zNodes);
            $("#addParent").bind("click", { isParent: true }, add);

        });
    </script>
</head>
<body>
    <br />
    @using (Html.BeginForm())
    {
        @Html.ValidationSummary(true)
        <div>
            <fieldset>
                <legend style="color: #4169E1;">已有情况类型(可更改)</legend>
                <div>
                    [ <a id="addParent" href="#" title="增加根节点" onclick="return false;">增加根节点</a> ]&nbsp;&nbsp;&nbsp;<span
                        style="color: #7B68EE;">说明：该树形结构只用于添加最多两层的数据结构</span>
                </div>
                <ul id="treeSituationType" class="ztree" style="overflow: scroll; width: 450px;">
                </ul>
            </fieldset>
        </div>
       
       
    }
</body>
</html>
